#!/usr/bin/env python

import sys
import os
import time
import db_util

def executeSchema(schemafile_path, config):
	cmd = "mysql -h %s --port %s -u%s -p%s < %s" %(db_util.getDBHost(config), db_util.getDBPort(config), db_util.getDBUser(config), db_util.getDBPassword(config), schemafile_path)
	print "Running system call %s" %(cmd)
	os.system(cmd)	

if __name__ == "__main__":
	if (len(sys.argv) != 4):
		print 'Proper usage is python createSchemaFromTemplate.py schema_label schema_sql_template_file configfile'	
	label = sys.argv[1]
	template = sys.argv[2]
	configfile = sys.argv[3]
	config = db_util.getConfig(configfile)
	executeSchema(template, config)


	print "Done creating schema file from template %s" % time.ctime()


